package com.jiegui.sms.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jiegui.common.annotation.Log;
import com.jiegui.common.core.controller.BaseController;
import com.jiegui.common.core.domain.AjaxResult;
import com.jiegui.common.enums.BusinessType;
import com.jiegui.sms.domain.SmsTemplate;
import com.jiegui.sms.service.SmsTemplateService;
import com.jiegui.common.utils.poi.ExcelUtil;
import com.jiegui.common.core.page.TableDataInfo;

/**
 * 短信模板Controller
 * 
 * @author wuqicheng
 * @date 2021-12-30
 */
@RestController
@RequestMapping("/sms/smsTemplate")
public class SmsTemplateController extends BaseController
{
    @Resource
    private SmsTemplateService smsTemplateService;

    /**
     * 查询短信模板列表
     */
    @PreAuthorize("@ss.hasPermi('sms:smsTemplate:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsTemplate smsTemplate)
    {
        startPage();
        List<SmsTemplate> list = smsTemplateService.selectSmsTemplateList(smsTemplate);
        return getDataTable(list);
    }

    /**
     * 导出短信模板列表
     */
    @PreAuthorize("@ss.hasPermi('sms:smsTemplate:export')")
    @Log(title = "短信模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmsTemplate smsTemplate)
    {
        List<SmsTemplate> list = smsTemplateService.selectSmsTemplateList(smsTemplate);
        ExcelUtil<SmsTemplate> util = new ExcelUtil<SmsTemplate>(SmsTemplate.class);
        return util.exportExcel(list, "短信模板数据");
    }

    /**
     * 获取短信模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('sms:smsTemplate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsTemplateService.selectSmsTemplateById(id));
    }

    /**
     * 新增短信模板
     */
    @PreAuthorize("@ss.hasPermi('sms:smsTemplate:add')")
    @Log(title = "短信模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsTemplate smsTemplate)
    {
        return toAjax(smsTemplateService.insertSmsTemplate(smsTemplate));
    }

    /**
     * 修改短信模板
     */
    @PreAuthorize("@ss.hasPermi('sms:smsTemplate:edit')")
    @Log(title = "短信模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsTemplate smsTemplate)
    {
        return toAjax(smsTemplateService.updateSmsTemplate(smsTemplate));
    }

    /**
     * 删除短信模板
     */
    @PreAuthorize("@ss.hasPermi('sms:smsTemplate:remove')")
    @Log(title = "短信模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsTemplateService.deleteSmsTemplateByIds(ids));
    }
}
